//index.js
//获取应用实例
const app = getApp()
var imagePaths = ['../../images/Capture001.png', '../../images/Capture002.png', '../../images/Capture003.png'];
var imageIndex=0;

Page({
  data: {
    imagePath:imagePaths[0],
    title: '开始',
    isRunning:false,
    userInfo: {},
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  change:function(e){
    imageIndex++;
    if(imageIndex>2)
    {
      imageIndex=0;
    }
    this.setData(
      {
        imagePath:imagePaths[imageIndex]
      }
    )
  },
  guess:function(e){
   let isRunning = this.data.isRunning;
   if(!isRunning)
   {
     this.setData(
       {
         title:'停止',
         isRunning:true
       }
     );
      this.timer=setInterval((function(){
        this.change()
      }).bind(this),1000);
   } 
   else{
     this.setData({
       title:'开始',
       isRunning:false
     });
  
   this.timer&&clearInterval(this.timer)
   }
  },
  onLoad: function () {
    console.log('onLoad')
    var that=this
    app.getUserInfo(function (userInfo){
      that.setData(
        {
          userInfo:userInfo
        }
      )
    })
  } 
})
